package com.hongyuan.venue.ui.person.view_mode;

import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.databinding.ObservableField;
import com.hongyuan.mvvmhabitx.binding.command.BindingAction;
import com.hongyuan.mvvmhabitx.binding.command.BindingCommand;
import com.hongyuan.venue.base.ItemViewModel;
import com.hongyuan.venue.data.md5.BaseUtil;
import com.hongyuan.venue.ui.main.activity.PayActivity;
import com.hongyuan.venue.ui.main.beans.V3SuccessBeans;
import com.hongyuan.venue.ui.person.beans.TrainningOrdersBean;
import java.util.ArrayList;
import java.util.List;

public class TrainningOrdersItemViewModel extends ItemViewModel<TrainningOrdersViewModel> {

    public ObservableField<TrainningOrdersBean.ListBean> entity = new ObservableField<>();

    public TrainningOrdersItemViewModel(@NonNull TrainningOrdersViewModel viewModel, TrainningOrdersBean.ListBean bean) {
        super(viewModel);
        entity.set(bean);
    }

    //取消订单
    public BindingCommand cancel = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            viewModel.itemClick(TrainningOrdersItemViewModel.this);

            viewModel.uc.cancelOrder.call();
        }
    });

    //去支付订单
    public BindingCommand goPay = new BindingCommand(new BindingAction() {
        @Override
        public void call() {

            Bundle bundle = new Bundle();
            bundle.putString("payPrice",entity.get().getO_money());
            bundle.putString("payOid",String.valueOf(entity.get().getO_id()));
            bundle.putSerializable("successBeans",getSuccessBeans());

            viewModel.startActivity(PayActivity.class,bundle);
        }
    });

    //去订单详情
    public BindingCommand goDetails = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            Bundle bundle = new Bundle();
            //bundle.putSerializable("orderBeans",entity.get());
            //viewModel.startActivity(MyOrderDetailActivity.class,bundle);
        }
    });

    /*
     * 组装订单显示信息
     * */
    private V3SuccessBeans getSuccessBeans(){
        V3SuccessBeans beans = new V3SuccessBeans();
        List<V3SuccessBeans.ItemConten> list = new ArrayList<>();

        V3SuccessBeans.ItemConten itemConten;

        beans.setType(V3SuccessBeans.TYPE.BUYCARD);
        beans.setTitleText("购卡订单");
        beans.setShowText("购买成功");
        beans.setBtn2Text("完成");

        itemConten = new V3SuccessBeans.ItemConten();
        itemConten.setContent(entity.get().getCt_name());
        itemConten.setItemTitle("课程名");
        list.add(itemConten);

        itemConten = new V3SuccessBeans.ItemConten();
        itemConten.setContent(entity.get().getCt_type() == 1 ? "一对一" : "一对多");
        itemConten.setItemTitle("类型");
        list.add(itemConten);

        itemConten = new V3SuccessBeans.ItemConten();
        itemConten.setContent("￥"+entity.get().getO_money());
        itemConten.setItemTitle("价格");
        list.add(itemConten);

        if(BaseUtil.isValue(entity.get().getO_coupon_money()) && Double.valueOf(entity.get().getO_coupon_money()) > 0){
            itemConten = new V3SuccessBeans.ItemConten();
            itemConten.setContent("-¥"+BaseUtil.getNoZoon(entity.get().getO_coupon_money()));
            itemConten.setItemTitle("优惠:");
            list.add(itemConten);
        }
        beans.setItemContens(list);

        return beans;
    }

}
